package com.itheima.boottlias.service.impl;

import com.itheima.boottlias.domain.entity.NameNum;
import com.itheima.boottlias.domain.entity.NameValue;
import com.itheima.boottlias.domain.vo.ClazzOption;
import com.itheima.boottlias.domain.vo.JobOption;
import com.itheima.boottlias.mapper.EmpMapper;
import com.itheima.boottlias.mapper.StudentMapper;
import com.itheima.boottlias.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ghy
 * @version 1.0
 * @since 2025-07-14 16:17
 */
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 统计各个岗位人数
     *
     * @return
     */
    @Override
    public JobOption getEmpJobData() {
        // 查询数据库获取各个岗位及人数
        List<NameNum> nameNumList = empMapper.getEmpJobData();
        // 处理数据
        List<String> jobList = nameNumList.stream().map(NameNum::getName).toList();
        List<Long> dataList = nameNumList.stream().map(NameNum::getNum).toList();
        return new JobOption(jobList, dataList);
    }

    /**
     * 统计各个性别人数
     *
     * @return
     */
    @Override
    public List<NameValue> getEmpGenderData() {
        return empMapper.getEmpGenderData();
    }

    @Override
    public List<NameValue> getStudentDegreeData() {
        return studentMapper.getStudentDegreeData();
    }

    @Override
    public ClazzOption getStudentCountData() {
        List<NameNum> nameNumList = studentMapper.getStudentCountData();
        List<String> clazzList = nameNumList.stream().map(NameNum::getName).toList();
        List<Long> dataList = nameNumList.stream().map(NameNum::getNum).toList();
        return new ClazzOption(clazzList, dataList);
    }

}
